package com.vcredit.creditcat.service;

import java.net.MalformedURLException;
import java.net.URL;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.tempuri.RCWebService;
import org.tempuri.RCWebServiceSoap;

@Service
public class GetWebApiFromRC {

	@Value("${rc.url}")
	private String rcUrl = "http://10.138.60.132:8000/GateWay/RCService.asmx?wsdl";

	private static Logger logger = LoggerFactory.getLogger(GetWebApiFromRC.class);

	private static RCWebServiceSoap RCWebServiceSoap = null;

	// -----------------------------loan
	// before-----------------------------------------------------
	public RCWebServiceSoap getRCWebServiceSoap() throws Exception {
		if (RCWebServiceSoap == null) {
			RCWebService rCWebService = null;
			try {
				rCWebService = new RCWebService(new URL(rcUrl));
				GetWebApiFromRC.RCWebServiceSoap = rCWebService.getRCWebServiceSoap();
			} catch (MalformedURLException e) {
				e.printStackTrace();
				logger.error(e.toString());
			} catch (Exception e) {
				e.printStackTrace();
				logger.error(e.toString());
				throw new Exception("Error when load VBS web service--RCService");
			}
		}
		return RCWebServiceSoap;
	}
}
